00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _DECONNECTION_HPP
00029 #define _DECONNECTION_HPP
00030
00031 #ifndef _DENET_HPP
00032 #include "deNet.hpp"
00033 #endif
00034
00035 #ifndef _DESYNCHOBJECT_HPP
00036 #include "deSynchObject.hpp"
00037 #endif
00038
00039 #ifndef _DEPACKETLIST_HPP
00040 #include "dePacketList.hpp"
00041 #endif
00042
00043 #include <SET>
00044 typedef std::set< dePacketList > aPacketLists;
00045
00046 class dePacket;
00047 class deNetUser;
00048 class deConnectionBin;
00049
00050
00051
00052
00053 typedef class DENET_API deConnection
00054 {
00055 friend class deConnectionProvider;
00056
00057 public:
00058
00059 enum fFlags
00060 {
00061 FLAG_FORCE_DISCONNECT = 0x0002,
00062 FLAG_CONFIRM_DELIVERY = 0x0004,
00063 };
00064
00065 enum eType
00066 {
00067 TYPE_UNKNOWN = 0,
00068 TYPE_TCP,
00069 TYPE_UDP,
00070 TYPE_DPLAY,
00071 TYPE_BSD
00072 };
00073
00074 deConnection(void);
00075 virtual ~deConnection(void);
00076
00077 eNetError ConnectTo( deNetAddress * pAddress );
00078 eNetError AttemptReset( DWORD dwFlags = NULL );
00079 eNetError Disconnect( DWORD dwFlags = NULL );
00080 eNetError BindAsServer( DWORD dwFlags = NULL );
00081 eNetError Send( WORD pNetMsgID, const void * pBuff, DWORD iSize, DWORD dwFlags = NULL );
00082 eNetError RecievePacket( dePacket * pPacket, DWORD dwFlags = NULL );
00083
00084
00085 deConnectionBin * GetConnectionBin( void );
00086 void SetConnectionBin( deConnectionBin * pBin );
00087 void SetOwner( deNetUser * own );
00088 DWORD GetDesc(void);
00089 eType GetType(void);
00090 bool IsReady(void);
00091 deSynchObject * GetSynchObject(void) { return &m_SynchObject; }
00092 deNetUser * GetOwner( void );
00093
00094 #ifdef DN_SESSION_TIME_INT64
00095 s64 GetAvgLag(void);
00096 #else
00097 float GetAvgLag(void);
00098 #endif
00099
00100 const deConnectionDesc * GetConnDesc(void) { return &m_ConnectionDesc; }
00101
00102 static DWORD GetMaxPacketSize(void) { return m_MaxPacketSize; }
00103
00104 protected:
00105
00106 virtual eNetError OnAttemptReset( DWORD dwFlags = NULL ) = 0;
00107 virtual eNetError OnBindAsServer( DWORD dwFlags = NULL ) = 0;
00108 virtual eNetError OnConnectTo( deNetAddress * pAddress ) = 0;
00109 virtual eNetError OnSend( WORD pNetMsgID, const void * pBuff, DWORD iSize, DWORD dwFlags ) = 0;
00110 virtual eNetError OnDisconnect( DWORD dwFlags = NULL ) = 0;
00111
00112 public:
00113
00114
00115 static int CompareConnections( const void *arg1, const void *arg2 );
00116
00117 struct deConfirmedReciept
00118 {
00119 int ID;
00120 int iSize;
00121 BYTE * buffer;
00122 float fTimeSent;
00123 float fMaxTime;
00124 };
00125
00126 struct dePartialReciept
00127 {
00128 int ID;
00129 int iSize;
00130 BYTE * buffer;
00131 int iIndex;
00132 int iTotalPackets;
00133 };
00134
00135 protected:
00136
00137 eType m_Type;
00138 deConnectionDesc m_ConnectionDesc;
00139
00140 private:
00141
00142 deSynchObject m_SynchObject;
00143 deConnectionBin * m_ParentConnectionBin;
00144 aPacketLists m_aPacketLists;
00145 deNetUser * m_Owner;
00146 bool m_bIsReady;
00147 DWORD m_dwDesc;
00148
00149 #ifdef DN_SESSION_TIME_INT64
00150 s64 m_LagHistory[4];
00151 s64 m_AvgLag;
00152 #else
00153 float m_LagHistory[4];
00154 float m_AvgLag;
00155 #endif
00156
00157 static DWORD m_MaxPacketSize;
00158
00159 } deConnection, *pdeConnection;
00160
00161 #endif